package components.utils;

import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * Enables a ComponentGroup only when there's a selection on the list provided.
 *
 * @author Juan
 */
public class ListSelectionEnabler implements ListSelectionListener {
    
    private ComponentGroup componentGroup;
    private JList list;

    public ListSelectionEnabler(ComponentGroup componentGroup, JList list) {
        this.componentGroup = componentGroup;
        this.list = list;
    }

    @Override
    public void valueChanged(ListSelectionEvent e) {
        boolean enable = false;
        if (list.getSelectedIndex() != -1) {
            enable = true;
        }
        componentGroup.setEnabled(enable);
    }

}
